//
//  UserVC.swift
//  DollarBuy
//
//  Created by 郑东喜 on 2016/11/7.
//  Copyright © 2016年 郑东喜. All rights reserved.
//  用户登陆主界面

import UIKit


class UserVC: MeBaseViewController {

    
//    微信工具类
    let wxtool = WXTool()
    
    //    QQ工具类
    let qqTool = QQTool()

    
    //用户名
    @IBOutlet weak var tfNum: UITextField!
    
    
    
    //密码
    @IBOutlet weak var tfPass: UITextField!
    
    @IBAction func wxshare(_ sender: Any) {
        
//        wxtool.share()
//        wxtool.share(titleStr: "测试", desc: "描述")
    }
    @IBAction func wxPay() {
//        wxtool.bizPay()
        
//
//        let dic = ["appid":"wxb4ba3c02aa476ea1",
//                   "partnerid":"1305176001",
//                   "package":"Sign=WXPay",
//                   "noncestr":"1f8494a98e2e015e82a93d2e7c6c1357",
//                   "timestamp":"1480236547",
//                   "prepayid":"wx201611271649076860a49b1f0687277322",
//                   "sign":"548541928770FBE0EB27E2FDB3A88B78"] as [String : Any]
        
//        let urlString = "http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios"
//        
//        postWithPath(path: urlString, paras: nil, success: { (response) in
//            //判读返回值是否为空
//            guard let dic = response as? NSDictionary else {
//                return
//            }
//            
//            print(dic)
//            
//            self.wxtool.sendWXPay(wxDict: dic)
//
//            
//        }) { (error) in
//            print(error.localizedDescription)
//        }
        let dic = ["prepayid":"wx201612081011346b1f1b76200572257571","noncestr":"c91f3cb2d8ac413491c2549f95d42a64","timestamp":"1481163094","sign":"37F7C4FB1660BA33C22389DD9EC760F8"]
        
        self.wxtool.sendWXPay(wxDict: dic as NSDictionary)
        
    }
}

// MARK:- 加载本地数据
extension UserVC {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        //加载本地 用户名 --- 便于测试
        if localSave.object(forKey: localName) as? String != nil {
            self.tfNum.text = localSave.object(forKey: localName) as? String
        } else {
            return
        }
        
        //加载本地 用户名密码
        if localSave.object(forKey: localPass) as? String != nil {
            self.tfPass.text = localSave.object(forKey: localPass) as? String
        } else {
            return
        }

    
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        NotificationCenter.default.removeObserver(self)
        print("移除通知")
    }
    
}




// MARK:- 跳转接口
extension UserVC {
    //qq登录
    @IBAction func qqLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("qq登录")))")
        
        
//        qqTool.qqLogin()
        
        
        
//        if _backMeVC == 1 {
//            self.navigationController!.popToRootViewController(animated: true)
//        }
        //qq登陆
//        QQTool.shared.qqShare()

    }
    
    
    //微信登录
    @IBAction func wechatLogin(_ sender: UIButton) {
        print("\((#file as NSString).lastPathComponent):(\(#line)):(\("微信登录")))")
        
//        wxtool.clickAuto()
    }

    //登陆
    @IBAction func loginSEL(_ sender: UIButton) {
        /**
         ## 登陆
         主要实现了登陆封装逻辑
         
         - tfNum    电话号码
         - tfPass   密码
         */
        self.login(tfNum: self.tfNum, tfPass: self.tfPass)
    }



}




